package com.glsc.ngateway.common.xir.repo;


import com.glsc.ngateway.common.xir.domain.TtrdOtcTrade;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TtrdOtcTradeRepository extends JpaRepository<TtrdOtcTrade, String>, JpaSpecificationExecutor<TtrdOtcTrade> {

    @Query(value = "select * from XIR_TRD.TTRD_OTC_TRADE where 1=1 " +
            "and (:code is null or TRDTYPE = :code) " +
            "and (:date is null or SETDATE = :date) " +
            "and (coalesce(:cashAccidList, null) is null or CASH_ACCID  in (:cashAccidList)) " +
            "and (coalesce(:secuAccidList, null) is null or SECU_ACCID  in (:secuAccidList)) " +
            "and (coalesce(:status, null) is null or ORDSTATUS  in (:status)) " +
            "", nativeQuery = true)
    List<TtrdOtcTrade> findAllByTrdtypeAndSetdateAndCashAccidInAndSecuAccidInAndOrdstatusIn(@Param("code") String code, @Param("date") String date,
                                                                                            @Param("cashAccidList") List<String> cashAccidList,
                                                                                            @Param("secuAccidList") List<String> secuAccidList,
                                                                                            @Param("status") List<String> status);

    @Query(value = "select * from XIR_TRD.TTRD_OTC_TRADE where 1=1 " +
            "and (:code is null or TRDTYPE = :code) " +
            "and (:date is null or SETDATE = :date) " +
            "and (coalesce(:status, null) is null or ORDSTATUS  in (:status)) " +
            "", nativeQuery = true)
    List<TtrdOtcTrade> findAllByTrdtypeAndSetdateAndOrdstatusIn(@Param("code") String code, @Param("date") String date,
                                                                                            @Param("status") List<String> status);


    List<TtrdOtcTrade> findAllByIntordidIn(List<String> intordidList);

    @Query(value = "select * from XIR_TRD.TTRD_OTC_TRADE where 1=1 " +
            "and (:code is null or TRDTYPE = :code) " +
            "and (:date is null or SETDATE = :date) " +
            "and (coalesce(:cashAccidList, null) is null or CASH_ACCID  in (:cashAccidList)) " +
            "and (coalesce(:secuAccidList, null) is null or SECU_ACCID  in (:secuAccidList)) " +
            "and (coalesce(:status, null) is null or ORDSTATUS  in (:status)) " +
            "and (coalesce(:intordIdList, null) is null or INTORDID  in (:intordIdList)) " +
            "", nativeQuery = true)
    List<TtrdOtcTrade> findAllByTrdtypeAndOrddateAndCashAccidInAndSecuAccidInAndOrdstatusInAndIntordidIn(@Param("code") String code,
                                                                                                         @Param("date") String date,
                                                                                                         @Param("cashAccidList") List<String> cashAccidList,
                                                                                                         @Param("secuAccidList") List<String> secuAccidList,
                                                                                                         @Param("status") List<String> status,
                                                                                                         @Param("intordIdList") List<String> intordIdList);
}